package com.hc.java.thread;

/**
 * @author huangchao E-mail:fengquan8866@163.com
 * @version 创建时间：2024/10/17 14:53
 */
public class 线程join {
    public static void main(String[] args) {
        Thread t0 = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(50000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("t0 is running " + System.currentTimeMillis());
            }
        });
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("t1 is running " + System.currentTimeMillis());
            }
        });
        Thread[] threads = new Thread[]{t0, t1};
        for (Thread thread : threads) {
            thread.start();
        }
        for (int i = 0; i < threads.length; i++) {
            try {
                // 第一个就阻塞住了，后面的都没有执行join方法，所以会一起执行完
                threads[i].join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("t" + i + " is over " + System.currentTimeMillis());
        }
    }
}
